package threadLocal;

public class T1Service {

    public void update() {
        //取出threadLocal1对象关联的对象
        /*
            public T get() {
                //1.获取当前线程
                Thread t = Thread.currentThread();
                //2.通过线程获取到对应的ThreadLocalMap
                ThreadLocalMap map = getMap(t);
                if (map != null) {
                    //3.如果map不为空，就获取当前threadLocal对应的Entry
                    ThreadLocalMap.Entry e = map.getEntry(this);
                    //4.如果Entry不为空
                    if (e != null) {
                        @SuppressWarnings("unchecked")
                        //5.返回当前threadLocal关联的值
                        T result = (T)e.value;
                        return result;
                    }
                }
            return setInitialValue();
    }
         */
        Object obj = ThreadLocalTest.threadLocal1.get();
        //获取当前线程名
        String name = Thread.currentThread().getName();
        System.out.println("在T1Service的update() 线程是 = " + name
                    + " dog = " + obj);
        //调用dao的update()
        new T2Dao().update();
    }

}
